#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinary Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


# Exercise 1.3.20 - Write a code fragment that puts the binary
representation of a positive integer into a string.

Syntax:
python int_to_binary_string.py 19 2


Notes:
int(sys.argv[1]) == Integer.parseInt(args[0])

sys is a required import here in order to use command line arguments.
https://docs.python.org/2/tutorial/stdlib.html

'''

import sys


def main():
    ''' Converts positive integer to base provided, prints representation '''

    try:
        integer = int(sys.argv[1])
        base = int(sys.argv[2])
        print '{} to be converted to base {}:'.format(integer, base)
    except IndexError:
        print 'Both an integer and a conversion base are required.'
        print 'Syntax:  python int_to_bin_string.py 19 2'
        sys.exit(0)

    output = ''
    while integer > 0:
        output = str(integer % base) + output
        integer = integer / base

    print output


if __name__ == '__main__':
    main()
